* Define programs for PSID project

cap program drop regIGCinc
program define regIGCinc 
	local cmline="`1'"
	qui reghdfe `cmline'
	ren INC INCBCK
	ren PINC PINCBCK
	egen INC=std(INCBCK) if e(sample)
	egen PINC=std(PINCBCK) if e(sample)
	qui reghdfe `cmline'
	drop INC PINC
	ren INCBCK INC
	ren PINCBCK PINC
end

cap program drop regIGCedu
program define regIGCedu
	local cmline="`1'"
	qui reghdfe `cmline'
	ren INC INCBCK
	ren EDU EDUBCK
	egen INC=std(INCBCK) if e(sample)
	egen EDU=std(EDUBCK) if e(sample)
	qui reghdfe `cmline'
	drop INC EDU
	ren INCBCK INC
	ren EDUBCK EDU
end

cap program drop regIGC
program define regIGC 
	local var1="`1'"
	local var2="`2'"
	local cmline="`3'"
	qui reghdfe `var1' `var2' `cmline'
	ren `var1' `var1'BCK
	ren `var2' `var2'BCK
	egen `var1'=std(`var1'BCK) if e(sample)
	egen `var2'=std(`var2'BCK) if e(sample)
	reghdfe `var1' `var2' `cmline'
	drop `var1' `var2'
	ren `var1'BCK `var1'
	ren `var2'BCK `var2'
end


cap program drop eststoreSD
program define eststoreSD
	su INC if e(sample)
	estadd scalar sdINC = r(sd)
	bysort son_id (year): gen INC3y=(INC[_n-1]+INC+INC[_n+1])/3
	su INC3y
	su FSONAGE if e(sample)
	gen MAGE=round(r(mean)/1)
	su INC3y if e(sample) & FSONAGE==MAGE
	estadd scalar sdINC3y = r(sd)
	drop INC3y MAGE
	su PINC if e(sample)
	estadd scalar sdPINC = r(sd)
end

cap program drop eststoreEDUSD
program define eststoreEDUSD
	su EDU if e(sample)
	estadd scalar sdEDU = r(sd)
	su PEDU if e(sample)
	estadd scalar sdPEDU = r(sd)
end




